{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# How Quantum Power Helps to Win a Coin Game\n",
    "\n",
    "A quantum coin game to illustrate the power of quantum superposition and interference - implemented by [Jan-R. Lahmann](https://twitter.com/JanLahmann) using [Qiskit](http://qiskit.org), [binder](https://mybinder.org) and [RISE](https://rise.readthedocs.io/).\n",
    "\n",
    "Inspired by the TED talk of Shohini Ghose  \n",
    "[\"Quantum computing explained in 10 minutes\"](https://www.ted.com/talks/shohini_ghose_quantum_computing_explained_in_10_minutes)\n",
    "\n",
    "The latest version of this notebook is available on https://github.com/Qiskit/qiskit-tutorials/tree/master/community/games.\n",
    "\n",
    "Click [here](https://ibm.biz/QiskitCoinGame) to run this notebook interactively in your browser.\n",
    "\n",
    "(hit space or right arrow to move to next slide)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "source": [
    "https://www.ted.com/talks/shohini_ghose_quantum_computing_explained_in_10_minutes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Usage instructions for the user interface\n",
    "\n",
    "1. \"Ctrl -\" and \"Ctrl +\" (or \"command -\", \"command +\") adjust the zoom level to fit the text to the browser window\n",
    "* Use \"space\" and \"shift  space\" to navigate through the slides \n",
    "* \"Shift Enter\" executes the interactive cells (might need to click the cell, first)\n",
    "* Execute the interactive cells on each slide (\"In [1]:\", etc)\n",
    "* In case a cell is not formatted correctly, try to double-click and then \"Shift Enter\" to re-execute\n",
    "* Interactive cells can be modified, if needed\n",
    "* \"X\" at the top left exits the slideshow and enters the jupyter notebook interface"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## The Coin Game\n",
    "\n",
    "Two players, A(lice) and B(ob), play a coin game.  \n",
    "\n",
    "1. The game starts with the coin showing Heads.\n",
    "* Player A starts and may either turn the coin or leave it as is. \n",
    "* The moves are hidden, i.e. not revealed to the other player.\n",
    "* B may now also turn the coin or leave it as is.\n",
    "* A then has the third and final move.\n",
    "* Now the coin gets revealed. \n",
    "* If it shows Heads, A wins; if it shows Tails, B wins."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "This notebook implements the coin game using Qiskit, an SDK by IBM to program quantum computers.  \n",
    "\n",
    "On three separate slides, the players can make their choice to either turn the coin (apply an \"X-Gate\") or leave it as is (apply an \"id-Gate\" / identity-Gate).  \n",
    "Heads is encoded by \"0\", Tails encoded by \"1\".  \n",
    "At the end, the quantum program evaluates the moves and declares the winner.  \n",
    "\n",
    "In a second phase, one player will be allowed to use an additional gate (\"coin move\"), which is only available in the Quantum world: the \"Hadamard Gate\".  \n",
    "Will this change the game?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "skip"
    }
   },
   "source": [
    "The game can also be played using the IBM \"Quantum Composer\" graphical UI https://quantumexperience.ng.bluemix.net/qx/editor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "scrolled": true,
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [],
   "source": [
    "# hit \"shift + Enter\" to execute this cell\n",
    "# loading some basic functions needed for the game\n",
    "from qiskit import ClassicalRegister, QuantumRegister, QuantumCircuit\n",
    "from qiskit import execute, BasicAer\n",
    "from qiskit.tools.visualization import plot_histogram, circuit_drawer\n",
    "from ipywidgets import interact"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [],
   "source": [
    "# hit \"shift + Enter\" to execute this cell\n",
    "# auxillary functions for the coin moves\n",
    "\n",
    "def MoveA1(move_A1): global moveA1; moveA1=move_A1;\n",
    "def MoveB1(move_B1): global moveB1; moveB1=move_B1;\n",
    "def MoveA2(move_A2): global moveA2; moveA2=move_A2;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [],
   "source": [
    "# hit \"shift + Enter\" to execute this cell\n",
    "# auxillary function to identify the winner\n",
    "\n",
    "def who_wins(counts):\n",
    "    if len(counts)==1 :\n",
    "        print('The winner is', 'A' if (\"0\" in counts) else 'B')\n",
    "    else:\n",
    "        count0=counts[\"0\"]\n",
    "        count1=counts[\"1\"]\n",
    "        print('The coin is in superposition of |0⟩ and |1⟩')\n",
    "        print('A wins with probability',  \"%.1f%%\" % (100.*count0/(count0+count1)))\n",
    "        print('B wins with probability',  \"%.1f%%\" % (100.*count1/(count0+count1)))\n",
    "    return()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Ready to play?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "## Player A makes the first move and applies an X-Gate (turn the coin) or id-Gate (leave it is)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "1793615253e642e29c40c4da7574d945",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(Dropdown(description='move_A1', options={'id Gate': 0, 'X Gate': 1}, value=0), Output())…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# hit \"shift + Enter\" to execute this cell\n",
    "# then make your choice using the drop-down widget\n",
    "interact(MoveA1, move_A1={'id Gate':0,'X Gate':1});"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Player B makes the his move and applies an X-Gate (turn the coin) or id-Gate (leave it is)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "4d93fd7dec9b4c80a2e00fb81aedaf34",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(Dropdown(description='move_B1', options={'id Gate': 0, 'X Gate': 1}, value=0), Output())…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# hit \"shift + Enter\" to execute this cell \n",
    "# you might need to click the cell, first, to activate it\n",
    "# then make your choice using the drop-down widget\n",
    "interact(MoveB1, move_B1={'id Gate':0,'X Gate':1});"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Player A makes his second move and applies an X-Gate (turn the coin) or id-Gate (leave it is)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f7fe0652ded54dc99171f5758f610046",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(Dropdown(description='move_A2', options={'id Gate': 0, 'X Gate': 1}, value=0), Output())…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# hit \"shift + Enter\" to execute this cell\n",
    "# you might need to click the cell, first, to activate it\n",
    "# then make your choice using the drop-down widget\n",
    "interact(MoveA2, move_A2={'id Gate':0,'X Gate':1});"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 1 0\n"
     ]
    }
   ],
   "source": [
    "# optional: print the three moves. \n",
    "# 0: id Gate (leave the coin unchanged), 1: X Gate (turn the coin)\n",
    "print(moveA1, moveB1, moveA2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAUwAAAB2CAYAAACj+KogAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAANfElEQVR4nO3df1TT9b8H8CdiDZONISL0iwaeUxZB4OSrX81QK3cMEIMsTuWpw9GV2eF4RA6/+uHZkZoe4pSd8rTvOYUp1qkwseKQ3pNyKjyzQOJ4T8dz5UdI4Q8MWEBdZHvfPzruhiJ7T7Z9Nnw+ztk5bJ/P9noO4eln25stSAghQERELk1ROgARUaBgYRIRSWJhEhFJYmESEUliYRIRSWJhEhFJYmESEUliYRIRSWJhEhFJYmESEUliYRIRSWJhEhFJYmESEUliYRIRSWJhEhFJYmESEUliYRIRSWJhEhFJYmESEUliYRIRSWJhEhFJYmESEUliYRIRSWJhEhFJYmESEUliYRIRSZqqdABS1saNG9Hc3OzzuUlJSXjzzTev6bpKZQYCM3cgZgYmlttbeIR5nWtubvb5L8REZyqR2RNz+b32/7mu8AiTkJSUhCNHjvhs3pIlSyZ8G77ODARm7kDMDHgmtzfwCJOISBILk4hIEguTiEgSC5OISBILk4hIEguTiDxOCIHh4WFcvHgRQohx93U4HOjs7PRRsolhYRKRR3R1dcFkMmHZsmXQarVQqVS48cYbcfPNNyMtLQ1vv/02+vv7R13H4XBg/fr10Ov16O7uVii5vOuqMCsrK91a36XX63Hw4EHvBSKaBHp7e5GbmwudToctW7bgjz/+wJNPPomtW7fCZDLBYDCgra0NeXl5uOWWW/Dqq69ieHjYWZYWiwXr1q1DdHS00nfFJb8tTLvdjoKCAkRGRkKtViM7Oxs9PT0+nZGZmYmamhqPz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mq1YvHixVCpVIiIiIBOp0Nra6tHcrmaTUTumWxlCShwhKnX69He3o4vvvgCaWlpsNlssFqtMBgMAACj0Yht27Zh6dKliIiIQGFhIQwGA3Q6HRoaGhAeHu68rfDwcFy4cMFj2cab7W18SE7kH8Z9tCcUUFlZKe68804xffp0ER0dLUpKSpzbRkZGRH5+voiIiBChoaHi0UcfFefPnxdCCFFXVyfy8vKc+2ZkZIiTJ0+OOaOsrEzcc889buUabzYRUUC9W1FfXx+WLVuGo0ePYnBwEKmpqWhubvbIc5hERK4E1PtharVabNy4EUuWLAEAVFRUsCyJyGcC6giTiEhJfvenkURE/oqFSUQkiYVJRCSJhUlEJImFSUQkiYVJRCSJhUlEJImFSUQkiYVJRCSJhUlEJImFSUQkiYVJRCSJhUlEJImFSUQkiYVJRCSJhUlEJImFSUQkiYVJRCSJhUlEJImFSUQkiYVJRCSJhUlEJImFSUQk6f8A6YB5QySBejwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 421.4x138.46 with 1 Axes>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# create the quantum circuit with the chosen coin moves\n",
    "q = QuantumRegister(1) # create a quantum register with one qubit\n",
    "# create a classical register that will hold the results of the measurement\n",
    "c = ClassicalRegister(1) \n",
    "qc = QuantumCircuit(q, c) # creates the quantum circuit\n",
    "backend = BasicAer.get_backend('qasm_simulator') # define the backend\n",
    "\n",
    "# 1. move of A\n",
    "qc.iden(q[0]) if (moveA1 == 0) else qc.x(q[0]) \n",
    "    \n",
    "# 1. move of B \n",
    "qc.iden(q[0]) if (moveB1 == 0) else qc.x(q[0])      \n",
    "\n",
    "# 2. move of A\n",
    "qc.iden(q[0]) if (moveA2 == 0) else qc.x(q[0]) \n",
    "    \n",
    "qc.measure(q, c) # Measure the qubits\n",
    "qc.draw(output='mpl') # plot the circuit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": false,
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'0': 200}\n",
      "The winner is A\n"
     ]
    }
   ],
   "source": [
    "# execute the quantum circiut (coin moves) and identify the winner\n",
    "\n",
    "job = execute(qc, backend, shots=200) # run the job simulation\n",
    "\n",
    "result = job.result() # grab the result\n",
    "\n",
    "counts = result.get_counts(qc) # results for the number of runs\n",
    "\n",
    "print(counts); # print the results of the runs\n",
    "who_wins(counts); # celebrate the winner"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Is there a safe strategy for A to always win the game? (or for B)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "It is easy to see that A and B will win with the same probability.  \n",
    "There is no strategy for A (or B) to increase this probability - and certainly no strategy to always win."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "Does this change if A has \"Quantum Power\" and may use \"H-Gates\" in addition to id and X?\n",
    "(B may still only use id- and X-Gates)\n",
    "\n",
    "Is there a safe strategy for A (or B) to always win using the new power?  \n",
    "How do you interpret this? Is it a \"sleight of hand\" or is there more behind it?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Ready to play with Quantum Power?\n",
    "A may now use id-, X- and H-gates.  \n",
    "B may use only id- and X-gates."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "## Player A makes the first move and applies an id-, X- or H-Gate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f32f5559b5d246c1aecb4f187f233367",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(Dropdown(description='move_A1', options={'id Gate': 0, 'X Gate': 1, 'H Gate': 2}, value=…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "interact(MoveA1, move_A1={'id Gate':0,'X Gate':1, 'H Gate':2});"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Player B makes his first move and applies an id- or X-Gate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "7a59c7c22fe446d09176ba2685d97092",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(Dropdown(description='move_B1', options={'id Gate': 0, 'X Gate': 1}, value=0), Output())…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "interact(MoveB1, move_B1={'id Gate':0,'X Gate':1});"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Player A makes her second move and applies an id-, X- or H-Gate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "619ec1309bdc4a4dae0516a90bfbf869",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(Dropdown(description='move_A2', options={'id Gate': 0, 'X Gate': 1, 'H Gate': 2}, value=…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "interact(MoveA2, move_A2={'id Gate':0,'X Gate':1, 'H Gate':2});"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": false,
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2 1 0\n"
     ]
    }
   ],
   "source": [
    "# optional: print the three moves. \n",
    "# 0: id Gate (leave the coin unchanged), 1: X Gate (turn the coin), 2: H Gate\n",
    "print(moveA1, moveB1, moveA2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "scrolled": true,
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAUwAAAB2CAYAAACj+KogAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAOsElEQVR4nO3dfUxT5+IH8C/WraC2tCLCnCLUxLkxFC1cvTqGOmfjwJfh3HTTzBAlUxdjRAPKXkwjWzGOGJfNrMmmzpeZbb7gNsP0Zkq2QZCBQPxlMT8sCDh8HVDFEaQ89w9j7ypoH6Ttad33kzSh55z2+bbSr+ecPqVBQggBIiJyq5/SAYiIAgULk4hIEguTiEgSC5OISBILk4hIEguTiEgSC5OISBILk4hIEguTiEgSC5OISBILk4hIEguTiEgSC5OISBILk4hIEguTiEgSC5OISBILk4hIEguTiEgSC5OISBILk4hIEguTiEgSC5OISBILk4hIEguTiEgSC5OISBILk4hIUn+lA5Cy1qxZg8rKSp+PGx8fj23btj3UbZXKDARm7kDMDPQtt7dwD/MfrrKy0ucviL6OqURmT4zL59r/x3WHe5iE+Ph4nDp1ymfjTZ06tc/34evMQGDmDsTMgGdyewP3MImIJLEwiYgksTCJiCSxMImIJLEwiYgksTCJyOOEEOjo6MDt27chhHjgtl1dXaivr/dRsr5hYRKRRzQ2NsJsNmP69OnQ6XRQq9V4/PHH8cQTTyAlJQUff/wxWltbXW7T1dWFFStWwGg0oqmpSaHk8v5Rhblr165eze8yGo04fvy49wIRPQKam5uRnp6O6OhobNq0CTdu3MDrr7+OzZs3w2w2w2QywWazYfXq1Rg2bBjef/99dHR0OMvSarVi+fLliIyMVPqhuOW3hXngwAEkJSVBq9Wif3/vzK93OBxYv349wsPDodFoMH/+fFy7ds25fu7cuSgoKPDK2IFs2LBh+Pzzz12WCSGg1Wpx+PBhhVLd382bNxEeHo6DBw86l/3111+YPHkyXnnlFXR1dSmYrmcvvvgivvjiix7X3X2uT58+7eNU3f3888+IjY3Fnj17sHr1apw/fx5lZWXYsWMHcnJy8O6772L37t34/fff8dtvv2H27Nkwm81ISEjA4sWLYbVasWHDBuTm5iIoKEjph+OW3xamXq/HypUrvfpZUovFgoKCApSWlqKxsREAsGTJEuf6uXPn4ujRo14bPxBdvHgRTU1NGDdunMtym82GGzduICEhQaFk9zdo0CCsW7cOZrMZQgg4HA68+uqrUKvV2LdvH/r187+XwYkTJ5Cent7jutraWty6dQtxcXE+TuWqqKgIM2fOhEajwenTp5Gfn4+YmJj7bm80GnHgwAEcOXIE586dw1dffYUVK1YETFkCChfm119/jbi4OAwaNAgzZ87E2rVrsWDBAgCAyWTCokWLYDAYvDa+1WpFVlYWDAYDQkNDsWXLFhQWFqKurg4AMG7cOPTv3x/l5eVeyxBoysrKoFKpEBsb67K8qqoKERERGDFihELJHuztt99GU1MTDh06hIyMDDQ2NqKgoABqtVrpaL1WXV2NMWPGICQkRLEMly5dQlpaGqKjo/HLL79g/PjxUrfr6urCsWPH0NHRgeDgYBQXF6Ozs9PLaT1HscLcvXs3MjMz8emnn6K1tRWpqanYvn279BN/L4vFgrFjx0pv39raivr6ehiNRueyUaNGQavVorq62rlszpw5PCz/m7KyMowePbrbi7Wqqsov9y7vGjhwINavX48333wTp06dQmFhIbRardKxevTTTz9h6NChzut3dyw0Gg1ee+01lJaWPvTrxFNWrVqFtrY2HD58GOHh4VK3+fs5yw0bNmDfvn2oqqqCxWLxclrPUaQwb926hbVr18Jqt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AAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 421.4x138.46 with 1 Axes>"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# create the quantum circuit with the chosen coin moves\n",
    "q = QuantumRegister(1) # create a quantum register with one qubit\n",
    "# create a classical register that will hold the results of the measurement\n",
    "c = ClassicalRegister(1) \n",
    "qc = QuantumCircuit(q, c) # creates the quantum circuit\n",
    "backend = BasicAer.get_backend('qasm_simulator') # define the backend\n",
    "\n",
    "# 1. move of A\n",
    "if   moveA1 == 0 : qc.iden(q[0])\n",
    "elif moveA1 == 1 : qc.x(q[0]) \n",
    "elif moveA1 == 2 : qc.h(q[0]) \n",
    "    \n",
    "# 1. move of B \n",
    "if   moveB1 == 0 : qc.iden(q[0])\n",
    "elif moveB1 == 1 : qc.x(q[0])     \n",
    "\n",
    "# 2. move of A\n",
    "if   moveA2 == 0 : qc.iden(q[0])\n",
    "elif moveA2 == 1 : qc.x(q[0]) \n",
    "elif moveA2 == 2 : qc.h(q[0]) \n",
    "\n",
    "qc.measure(q, c) # Measure the qubits\n",
    "qc.draw(output='mpl') # plot the circuit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'1': 100, '0': 100}\n",
      "The coin is in superposition of |0⟩ and |1⟩\n",
      "A wins with probability 50.0%\n",
      "B wins with probability 50.0%\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAc0AAAE3CAYAAADITBpiAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAd20lEQVR4nO3df5RV5X3v8fdXYPihYhhEHERAhEuH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T6vovT95y312SVJ0lBR1+80M/MrETEe+AjQQul2kosys3vU2AKcWdH+QET8GvDnlO7N3A18B7ixfBEQmflMRFwE/BlwLbAF+GBmPlin3ZIkDRF1vU+z0XghkCSpp+bm5hWZuaC3dc49K0lSQYamJEkFGZqSJBVkaEqSVJChKUlSQYamJEkFGZqSJBVkaEqSVJChKUlSQYamJEkFGZqSJBVkaEqSVJChKUlSQYamJEkFGZqSJBVkaEqSVJChKUlSQYamJEkFGZpD3MMPP8w555zD2WefzW233XbQ+u9///tMnTqV888/n/PPP5/FixcfctsdO3Zw8cUXs2DBAi6++GJ+/vOf12VfpGOdx+vgMzSHsK6uLm666Sa++tWv8vjjj/Pggw/y05/+9KB25557Lo8++iiPPvooN9100yG3ve2221i4cCHLly9n4cKFvR7ckqrj8doYDM0hbMWKFZxxxhlMmzaNpqYmLrnkEh566KEj3vahhx7isssuA+Cyyy5jyZIlA7YP0lDh8doYDM0hrKOjg9NOO+3V95MmTaKjo+Ogdj/+8Y8577zz+I3f+A3a29sPue3zzz/PqaeeCsCpp57Ktm3bBnI3pCHB47UxDB/sAjR4MvOgZRHxmvevf/3rWbVqFSeccALf+c53uPzyy1m+fHmhbSXVjsdrY3CkOYRNmjSJZ5999tX3W7ZsefV/nN3Gjh3LCSecAMCiRYvYt28f27dv73fbU045heeeew6A5557jgkTJgz0rkjHPI/XxmBoDmFnnXUW69evZ+PGjXR2dvKNb3yDCy+88DVttm7d+ur/UlesWMGBAwdobm7ud9sLL7yQBx54AIAHHniAt771rfXdMekY5PHaGDw9O4QNHz6cxYsX8653vYuuri7e+9730trayl/91V8B8P73v59vfetb3HPPPQwfPpxRo0Zx9913ExF9bgtwww038IEPfID777+fyZMnv9qfpMPn8doYordz3UNFW1tbLlu2bLDLkCQ1kObm5hWZuaC3dZ6elSSpIENTkqSCDE1JkgoyNCVJKsjQlCSpIENTkqSCDE1JkgoyNCVJKsjQlCSpIENTkqSCDE1JkgpywvYauOm+cYNdggbA4it2DHYJGiAes8emeh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lP5D+xngm8CnI+LiiDgzIkaX24wG/rI8aYwOgyNNHaR8YP0DpQeA/ybwb5l5oEeb64Hfysw3DEKJknqIiLsoPRRjMXAJcAVwJrAWWAI8AswCbs/MpsGq82jnSFMHKT/0+4+A0cBfA78ZEadHxPEAETEGWEhpGkRJgywihlM6O/TzzFyfmbdk5jzgF4HvUgrQrwKfBb40eJUe/Rxpqk8RMRf4Y+DtwCuUniizjdJTZTqAqzLzycGrUFK3iBgHTMzMn0ZEE7CvxxzdlwJfBs7yWoTDZ2jqkMq3n7wNeAewh9II82uZ+dNBLUxSvyLiOEr/zndFxG9TOjU7ZrDrOpoZmqpKRBzX8/tNSY0vIm4EhmXmpwe7lqOZoSlJQ0BEjAC6/E/vkTE0JUkqyKtnJUkqyNCUJKkgQ1OSpIIMTUmSCjI0JUkq6P8DiYgGK/sz4oEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# execute the quantum circiut (coin moves) and identify the winner\n",
    "\n",
    "job = execute(qc, backend, shots=200) # run the job simulation\n",
    "\n",
    "result = job.result() # grab the result\n",
    "\n",
    "counts = result.get_counts(qc) # results for the number of runs\n",
    "\n",
    "print(counts); # print the results of the runs\n",
    "who_wins(counts); # celebrate the winner\n",
    "\n",
    "plot_histogram(counts) # Visualise the results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Want to make some own experiments to understand the state of the qubit (\"quantum coin\")?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAUwAAAB2CAYAAACj+KogAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdh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d3P7keYLS0tCAwMxKZNmzBnzpwOl83JycG8efOQn5+PkSNHAgCys7Px+eefAwDWr1+PF1980SZ11dbWIiAgAFVVVQgODja3BwYGIjU11WqtXZWcntWt2yciOWlJCQ+dZ/ePRubn58PFxQVvvPFGh8vt3r0bixYtQl5enjksm5qakJGRgVOnTuHGjRuIiorCmTNnoFKpulyXWn33gvT9p/5NTU3QaDRd3r41Hf0jETkjIQRcnHjMZXvsfkp+9epVeHl5dfhCbtmyBYsWLcL+/fsRFRVlbi8sLMS4cePg5uYGb29vBAUFobKy0iZ1abVaBAQEoKSkxNxWVVUFo9H4ty4JED3qelpYAgocYer1elRXV2P//v2IiYmB0WhEYWEhoqOjAQCZmZn48MMPcfjwYURERFis29DQAC8vL/NjLy8vNDQ02Ky2hIQEpKenIyoqCt7e3khKSkJ0dLRdbvjwlJzIMXR4ticUsHXrVjFkyBDh4eEh/Pz8xJo1a8zzAAhXV1fh4eFhMQkhxKFDh8SyZcvMy06ZMkWcO3eu3T5SU1PFs88+26m67ty5IxITE4W3t7fw9PQUr7zyirhy5crfeIZE1BM51bcVNTU1YcKECTh16hRaWloQGRmJ0tJSm1zDJCKyxqm+D1Or1WL58uUYP348ACAjI4NhSUR241RHmERESnK4j0YSETkqBiYRkSQGJhGRJAYmEZEkBiYRkSQGJhGRJAYmEZEkBiYRkSQGJhGRJAYmEZEkBiYRkSQGJhGRJAYmEZEkBiYRkSQGJhGRJAYmEZEkBiYRkSQGJhGRJAYmEZEkBiYRkSQGJhGRJAYmEZEkBiYRkaR/A0SgRIaDZwPWAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 421.4x138.46 with 1 Axes>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# create the quantum circuit with the chosen coin moves\n",
    "q = QuantumRegister(1) # create a quantum register with one qubit\n",
    "# create a classical register that will hold the results of the measurement\n",
    "c = ClassicalRegister(1) \n",
    "qc = QuantumCircuit(q, c) # creates the quantum circuit\n",
    "backend = BasicAer.get_backend('qasm_simulator') # define the backend\n",
    "\n",
    "\n",
    "# define the quantum gates (=coin moves) as you like\n",
    "# you could also try change the number of moves to just 1 or 2\n",
    "#qc.iden(q[0])\n",
    "#qc.x(q[0]) \n",
    "#qc.h(q[0]) \n",
    "\n",
    "qc.iden(q[0])\n",
    "qc.x(q[0]) \n",
    "qc.h(q[0])\n",
    "\n",
    "qc.measure(q, c) # Measure the qubits\n",
    "qc.draw(output='mpl') # plot the circuit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'1': 100, '0': 100}\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAc0AAAE3CAYAAADITBpiAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjAsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+17YcXAAAd20lEQVR4nO3df5RV5X3v8fdXYPihYhhEHERAhEuHHyGj1NbcKuYm9BrTm0aTRrMSq0mtS101y3pb07RpkzT3xhtirDaJNdFabeyN+WHapC3eEKWNSbRJQEoEJwSLQJEREYlS+TEwfO8f54w9DjPDPnDmzIF5v9aaxTl7P/s5382szYdnn72fHZmJJEk6tOMGuwBJko4WhqYkSQUZmpIkFWRoSpJUkKEpSVJBhqYkSQUZmpIkFVT30IyI6yLimYjYExErIuK8Q7SPiLghIn4aEXsjoiMi/k+PNgvLfe2JiPURcc3A7oUkaSiqa2hGxKXA7cAngTbgMeChiJjSz2afAa4DPgS0AhcBj1b0eQawpNxXG3Az8NmIeOdA7IMkaeiKes4IFBE/BH6Smb9dsWwd8PXM/HAv7WcBq4HXZ2Z7H31+CrgkM2dWLLsbmJOZ59Z6HyRJQ1fdRpoR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gQ1OSpIIMTUmSCjI0JUkq6P8DiYgGK/sz4oEAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 504x360 with 1 Axes>"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# execute the quantum circiut (coin moves) and identify the winner\n",
    "\n",
    "job = execute(qc, backend, shots=200) # run the job simulation\n",
    "\n",
    "result = job.result() # grab the result\n",
    "\n",
    "counts = result.get_counts(qc) # results for the number of runs\n",
    "\n",
    "print(counts); # print the results of the runs\n",
    "\n",
    "plot_histogram(counts) # Visualise the results\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Some Quantum Theory related to this Coin Game\n",
    "\n",
    "(hint: In case a cell is not formatted correctly, try to double-click and then \"Shift Enter\" to re-execute)  \n",
    "A (general) quantum state can be written as $\\;\\; \\alpha |0\\rangle + \\beta |1\\rangle $.  \n",
    "It is called a superposition of $\\;|0\\rangle\\;$  and $\\;|1\\rangle\\;$.  \n",
    "$ \\alpha , \\beta $ are generalized probabilities (for measuring 0 or 1) with $\\; \\alpha , \\beta \\in \\mathbb{C},\\; |\\alpha|^2 + |\\beta|^2 = 1$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "A quantum gate acting on a single qubit can be defined by its action on the basis vectors $|0\\rangle$  and $|1\\rangle$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "X-Gate maps $\\;|0\\rangle$  to $|1\\rangle\\;$  and $\\;|1\\rangle$  to $|0\\rangle$. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "Hadamard-Gate maps $\\;|0\\rangle\\;$ to $\\;\\frac{|0\\rangle + |1\\rangle}{\\sqrt{2}}\\;\\;$  and   $\\;\\;|1\\rangle\\;$ to $\\;\\frac{|0\\rangle - |1\\rangle}{\\sqrt{2}}$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "If we can show that \n",
    "$$ H(\\; id( H(|0\\rangle) ) \\;) = |0\\rangle\\, $$\n",
    "and \n",
    "$$ H(\\;\\, X( H(|0\\rangle) ) \\;)  = |0\\rangle, $$  \n",
    "it becomes clear that if A applies an H-Gate in both of her moves, she wins the game - independent of the move of B (X or id).\n",
    "\n",
    "Remember: Heads is encoded by $|0\\rangle$, Tails encoded by $|1\\rangle$. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "The first equation holds because:  \n",
    "\n",
    "\\begin{align*} \n",
    "H(\\; id(\\; H(|0\\rangle) \\;)\\; ) \n",
    "      = &\\;\\; H(\\; H(|0\\rangle)\\; )  \\\\\n",
    "      = &\\;\\; H(\\; \\frac{|0\\rangle + |1\\rangle}{\\sqrt{2}}\\;) \\\\\n",
    "      = &\\;\\; \\frac{1}{\\sqrt{2}}\\;(\\; H(|0\\rangle) + H(|1\\rangle) \\;) \\\\\n",
    "      = &\\;\\; \\frac{1}{\\sqrt{2}}\\;(\\;\\frac{|0\\rangle + |1\\rangle}{\\sqrt{2}} + \\frac{|0\\rangle - |1\\rangle}{\\sqrt{2}}\\;) \\\\\n",
    "      = &\\;\\; \\frac{1}{{2}}\\; (\\;|0\\rangle + |1\\rangle + |0\\rangle - |1\\rangle\\; )\\\\\n",
    "      = &\\;\\; |0\\rangle\n",
    "\\end{align*}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "This fundamentaly uses superposition (created by the H-Gate) and in the last equality (destructive) interference of the amplitudes (generalized probabilities) of $|1\\rangle$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "In case B choses to use an X-Gate instead of id, the following identity\n",
    "\n",
    "$$ X(\\; H(|0\\rangle) \\;) = X\\; (\\;\\frac{|0\\rangle + |1\\rangle}{\\sqrt{2}}\\; ) = \\frac{|1\\rangle + |0\\rangle}{\\sqrt{2}} = H(|0\\rangle) $$\n",
    "\n",
    "can be used to show that the final state is $ |0\\rangle$:\n",
    "\n",
    "$$ H(\\; X( H(|0\\rangle) ) \\;) = H(\\; H(|0\\rangle)\\; ) = |0\\rangle $$\n",
    "\n",
    "[These charts](https://github.com/JanLahmann/Fun-with-Quantum/raw/master/QuantumTheory-for-QuantumCoinGame.pdf) explain a bit more of the quantum theory and formalism required to prove the above identities, in case you are interested."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "We now have shown that the final state is always $ |0\\rangle$, independent of the move of B.  \n",
    "\n",
    "Thus, A wins the game with certainty, if she applies an H-Gate in both of her moves."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "How do you interpret this?  \n",
    "Is it a \"sleight of hand\" or is there more to it?  "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "Hint:  \n",
    "What if an \"algorithm\" could use the \"extra moves\" to calculate answers that cannot be calculated (or take much longer to be calculated) with \"classical moves\"?"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "celltoolbar": "Slideshow",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.0"
  },
  "latex_envs": {
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 0
  },
  "livereveal": {
   "autolaunch": true
  },
  "nav_menu": {},
  "toc": {
   "navigate_menu": true,
   "number_sections": true,
   "sideBar": true,
   "threshold": 6,
   "toc_cell": false,
   "toc_section_display": "block",
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
